package com.bishe.demo.modules.hotel.hotelDetail.dao;

import com.bishe.demo.modules.hotel.hotelDetail.entity.Detail;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface DetailDao {
    @Insert("insert into hotel_detail values(#{detailId},#{startingYear},#{decoratedYear},#{roomNumber},#{contactName},#{contactPhone},#{detailDetail})")
    @Options(useGeneratedKeys = true, keyProperty = "detailId", keyColumn = "detail_id")
    void insertDetail(Detail detail);

    @Select("select * from hotel_detail where detail_id=#{userId}")
    Detail getDetailByUserId(int userId);

    @Select("select * from hotel_detail")
    @Results(id = "detailResult", value = {
            @Result(column = "detail_id", property = "detailId"),
            @Result(column = "detail_id", property = "detailImages",
                    javaType = List.class,
                    many = @Many(select = "com.bishe.demo.modules.hotel.common.dao.HotelImageDao.getImagesByDetailId")),
    })
    List<Detail> getDetails();

    @Select("select * from hotel_detail where detail_id=#{mainId}")
    @ResultMap(value = "detailResult")
    Detail getDetailByMainId(int mainId);

    @Select("select * from hotel_detail where detail_id=#{hotelId}")
    @ResultMap(value = "detailResult")
    Detail getDetailByHotelId(int hotelId);

    @Update("update hotel_detail set starting_year=#{startingYear},decorated_year=#{decoratedYear},room_number=#{roomNumber},contact_name=#{contactName},contact_phone=#{contactPhone},detail_detail=#{detailDetail} where detail_id=#{detailId}")
    void updateDetail(Detail detail);

    @Delete("delete from hotel_detail where detail_id=#{hotelId}")
    void deleteDetailByHotelId(int hotelId);
}
